package com.dalin.framework.util;

import java.lang.reflect.Field;

/**
 * 字符串相关方法
 */
public class StringUtil {
	/**
	 * content : 输出STUDENT 类所有属性值
	 * author : najianlin
	 * email : naariahlin@163.com
	 * date : 2024-10-30 10:19
	 * version: V.1.0.0
	 */
	public static void printValues(Object obj) throws Exception {
		if (obj == null) {
			System.out.println("printValues parameter obj is null");
			return;
		}
		Class clazz = obj.getClass();
		System.out.println("printValues parameter obj="+clazz.getName()+": {");
		System.out.print("  ");
		Field[] fields = clazz.getDeclaredFields();
		for (Field field : fields) {
			field.setAccessible(true);
			System.out.print(field.getName() + ":" + field.get(obj) + ", ");
		}
		System.out.println("\n}");
	}

	/**
	 * 将以逗号分隔的字符串转换成字符串数组
	 * 
	 * @param valStr
	 * @return String[]
	 */
	public static String[] StrList(String valStr) {
		int i = 0;
		String TempStr = valStr;
		String[] returnStr = new String[valStr.length() + 1 - TempStr.replace(",", "").length()];
		valStr = valStr + ",";
		while (valStr.indexOf(',') > 0) {
			returnStr[i] = valStr.substring(0, valStr.indexOf(','));
			valStr = valStr.substring(valStr.indexOf(',') + 1, valStr.length());

			i++;
		}
		return returnStr;
	}
}
